package com.nbjtjc.safe.api.sys;


import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.MyPageInfo;
import com.nbjtjc.safe.bean.Page;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.sys.SysOption;
import com.nbjtjc.safe.service.sys.SysOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统选项
 */
@RequestMapping("/sys/option")
@RestController
@CrossOrigin("*")
public class SysOptionController {

    @Autowired
    private SysOptionService optionService;


    @RequestMapping(value="/update",method = {RequestMethod.POST})
    public Result update(SysOption sysOption){
        Result result=new Result<>();
        try {
            result=optionService.update(sysOption);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse("插入失败");
            return  result;
        }
        return result;
    }


    @RequestMapping(value="/add",method = {RequestMethod.POST})
    public Result add(SysOption sysOption){
        Result result=new Result<>();
        try {
            result=optionService.add(sysOption);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse("插入失败");
            return  result;
        }
        return result;
    }

    @RequestMapping(value="/delete",method = {RequestMethod.POST})
    public Result<Boolean> delete(SysOption sysOption){
        Result<Boolean> result=new Result<>();
        try {
            result=optionService.delete(sysOption);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse("删除失败："+e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/find" ,method = {RequestMethod.GET,RequestMethod.POST})
    public PageInfo find(Page  page,SysOption sysOption){
        MyPageInfo myPageInfo=new MyPageInfo<>();
        try {
            myPageInfo=optionService.find(page,sysOption);
            return myPageInfo;
        } catch (Exception e) {
            e.printStackTrace();
            myPageInfo.setCode(400);
            myPageInfo.setMsg("失败");
        }
        return myPageInfo;
    }
}
